<?php
session_start();//session开始标签，在最顶部写。
?>
<head>
<title>教师课程管理页面</title>
<style type="text/css">
body {
	background-image: url(background2.jpg);
}
</style>
</head>

<body>
<?php
$username = $_SESSION["username"];
//$username = "student1";
echo "尊敬的用户：".$username."<br>";

/*---------------------一、PHP文件引用----------------------------------*/
require_once 'response.php';
require_once 'connect_config.php'; 
require('../config.php');
require_once($CFG->libdir .'/enrollib.php');

/*---------------------二、变量参数定义-------------------------------*/
$msg = "";
$courses = array();

/*---------------------三、数据库连接--------------------------------*/
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME,DB_PORT) or die('数据库连接失败');

/*---------------------四、查询学生ID--------------------------------*/
if($username)
{
	$query = "select * from mdl_user where username = '$username'";
	$data1 = mysqli_query($conn, $query);         
	$row = mysqli_fetch_array($data1);
	if($row)
	{
		$id = $row['id'];
	}
	else
	{
		$msg =	mysqli_errno($conn);
	}
}

/*---------------------五、进行课程查询--------------------------------*/
if($id)
{
    $query2 = "select * from mdl_role_assignments where userid = '$id'";
	$data2 = mysqli_query($conn, $query2);
	$row2 = mysqli_fetch_array($data2);
	$roleid = $row2['roleid'];
	if($roleid>4)
	{
		die("you are not a user equals techer!");	
	}
	else
	{
//		echo "欢迎进行课程管理！<br>";
		if($roleid==4)
		{
			echo "Sorry!You are a teacher who can not edit courses<br>";
		}	
		else
		{
			$url="course_manage-c.php";
			echo "<script language='javascript' type='text/javascript'>";
			echo "alert('Welcome to courses management');location.href='$url'";
			echo "</script>";
		}
	}
}
else
{
	$status = false;
	$msg = "failure";
	echo Response::json($status,$msg,$data);
}
?>
</body>
</html>
